#include "base/event_loop.h"

EventLoop::EventLoop()
  : event_base_(NULL) {
}


EventLoop::~EventLoop() {
}

bool EventLoop::Initialize() {
  if (event_base_ != NULL) {
    std::cerr << "Failure to reinit event loop!" << std::endl;
    return false;
  }

  event_base_ = event_base_new();
  if (event_base_ == NULL) {
    std::cerr << "Failure to init event loop!" << std::endl;
    return false;
  }

  return true;
}

void EventLoop::Run() {
  event_base_loop(event_base_, EVLOOP_NO_EXIT_ON_EMPTY);
}

void EventLoop::Stop() {
  event_base_loopbreak(event_base_);
}

void EventLoop::Uninitialize() {
  if (event_base_ != NULL) {
    event_base_free(event_base_);
    event_base_ = NULL;
  }
}
